package cn.com.netedge.iot.frontend.biz.utils;

import cn.com.netedge.iot.common.constants.MqConstants;
import cn.com.netedge.iot.common.mq.MqMessageListener;
import cn.com.netedge.iot.common.utils.BaseJmsMsgUtil;
import cn.com.netedge.iot.frontend.biz.config.BpConfig;
import cn.com.netedge.iot.frontend.biz.mq.ReceiveMessageConsumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@RefreshScope
public class JmsMsgUtil extends BaseJmsMsgUtil {
    private static final Logger logger = LoggerFactory.getLogger(JmsMsgUtil.class);

    @Override
    public void subscribeQueues() {
        List<String> queueList = new ArrayList<>();
        queueList.add(MqConstants.QUEUE_UP_MESSAGE_NORMAL);
        queueList.add(MqConstants.QUEUE_UP_MESSAGE_EMERGENCY);
        subscribeQueue(queueList);
    }

    @Override
    public MqMessageListener getMessageListener(String queueName) {
        MqMessageListener listener;
        if (MqConstants.QUEUE_UP_MESSAGE_NORMAL.equals(queueName) || MqConstants.QUEUE_UP_MESSAGE_EMERGENCY.equals(queueName)) {
            listener = BpConfig.appContext.getBean(ReceiveMessageConsumer.class);
        } else {
            logger.debug("queueName:{} not support subscribe");
            return null;
        }
        return listener;
    }


}
